#!/usr/bin/bash

# Copyright (c) 2023. Huawei Technologies Co.,Ltd.ALL rights reserved.
# This program is licensed under Mulan PSL v2.
# You can use it according to the terms and conditions of the Mulan PSL v2.
#          http://license.coscl.org.cn/MulanPSL2
# THIS PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.

###################################
#@Author    :   gaoyue
#@Contact   :   2829807379@qq.com
#@Date      :   2022/8/30
#@License   :   Mulan PSL v2
#@Desc      :   Test "libsmi" command
###################################

source "${OET_PATH}"/libs/locallibs/common_lib.sh

function pre_test() {
    LOG_INFO "Start to prepare the test environment"
    DNF_INSTALL "libsmi"
    cp /usr/share/mibs/ietf/IF-MIB IF-MIB
    LOG_INFO "End to prepare the test environment"
}
function run_test() {
    LOG_INFO "Start to run test."
    smidump -f smiv2  IF-MIB 2>&1 | grep -e "IF-MIB DEFINITIONS ::= BEGIN"
    CHECK_RESULT $? 0 0 "L$LINENO: -f smiv2 No Pass"
    smidump -f sppi  IF-MIB 2>&1 | grep -e "-- This SPPI module has been generated by smidump"
    CHECK_RESULT $? 0 0 "L$LINENO: -f sppi No Pass"
    smidump -f scli  IF-MIB 2>&1 && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli No Pass"
    smidump -f scli  --scli-prefix=huawei IF-MIB 2>&1 && grep -e "huawei" if-mib.c | head -10 && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli --scli-prefix=string No Pass"
    smidump -f scli  --scli-include=huawei IF-MIB 2>&1 && grep -e "huawei" if-mib.c && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli --scli-include=string No Pass"
    smidump -f scli  --scli-exclude=huawei IF-MIB 2>&1 && grep -e "huawei" if-mib.c && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli --scli-exclude=string No Pass"
    smidump -f scli  --scli-set IF-MIB 2>&1 && grep -e "smidump -f scli --scli-set IF-MIB" if-mib.c && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli --scli-set No Pass"
    smidump -f scli  --scli-create IF-MIB 2>&1 && grep -e "RowStatus" if-mib.c && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli --scli-create No Pass"
    smidump -f scli  --scli-delete IF-MIB 2>&1 && grep -e "RowStatus" if-mib.c && rm -rf if-mib.*
    CHECK_RESULT $? 0 0 "L$LINENO: -f scli --scli-delete No Pass"
    LOG_INFO "End to run test."
}
function post_test() {
    LOG_INFO "Start to restore the test environment."
    DNF_REMOVE "$@"
    rm -rf ./result* ./IF_MIB* ./if-mib*
    LOG_INFO "End to restore the test environment."
}

main "$@"
